home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / uplevel.test < prev    next >
Text File  |  1992-12-23  |  3KB  |  99 lines

  1. # Commands covered:  uplevel
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /rel/cvsfiles/devo/tcl/tests/uplevel.test,v 1.1.1.1 1992/11/07 04:47:01 zoo Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. proc a {x y} {
  21.     newset z [expr $x+$y]
  22.     return $z
  23. }
  24. proc newset {name value} {
  25.     uplevel set $name $value
  26.     uplevel 1 {uplevel 1 {set xyz 22}}
  27. }
  28.  
  29. test uplevel-1.1 {simple operation} {
  30.     set xyz 0
  31.     a 22 33
  32. } 55
  33. test uplevel-1.2 {command is another uplevel command} {
  34.     set xyz 0
  35.     a 22 33
  36.     set xyz
  37. } 22
  38.  
  39. proc a1 {} {
  40.     b1
  41.     global a a1
  42.     set a $x
  43.     set a1 $y
  44. }
  45. proc b1 {} {
  46.     c1
  47.     global b b1
  48.     set b $x
  49.     set b1 $y
  50. }
  51. proc c1 {} {
  52.     uplevel 1 set x 111
  53.     uplevel #2 set y 222
  54.     uplevel 2 set x 333
  55.     uplevel #1 set y 444
  56.     uplevel 3 set x 555
  57.     uplevel #0 set y 666
  58. }
  59. a1
  60. test uplevel-2.1 {relative and absolute uplevel} {set a} 333
  61. test uplevel-2.2 {relative and absolute uplevel} {set a1} 444
  62. test uplevel-2.3 {relative and absolute uplevel} {set b} 111
  63. test uplevel-2.4 {relative and absolute uplevel} {set b1} 222
  64. test uplevel-2.5 {relative and absolute uplevel} {set x} 555
  65. test uplevel-2.6 {relative and absolute uplevel} {set y} 666
  66.  
  67. test uplevel-3.1 {error: non-existent level} {
  68.     list [catch c1 msg] $msg
  69. } {1 {bad level "#2"}}
  70. test uplevel-3.2 {error: non-existent level} {
  71.     proc c2 {} {uplevel 3 {set a b}}
  72.     list [catch c2 msg] $msg
  73. } {1 {bad level "3"}}
  74. test uplevel-3.3 {error: already at global level} {
  75.     list [catch {uplevel gorp} msg] $msg
  76. } {1 {already at top level}}
  77. test uplevel-3.4 {error: already at global level} {
  78.     list [catch {uplevel 1 gorp} msg] $msg
  79. } {1 {already at top level}}
  80. test uplevel-3.5 {error: not enough args} {
  81.     list [catch uplevel msg] $msg
  82. } {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}
  83. test uplevel-3.6 {error: not enough args} {
  84.     proc upBug {} {uplevel 1}
  85.     list [catch upBug msg] $msg
  86. } {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}
  87.  
  88. proc a2 {} {
  89.     uplevel a3
  90. }
  91. proc a3 {} {
  92.     global x y
  93.     set x [info level]
  94.     set y [info level 1]
  95. }
  96. a2
  97. test uplevel-4.1 {info level} {set x} 1
  98. test uplevel-4.2 {info level} {set y} a3
  99.